﻿using System;
using System.Threading.Tasks;
using LiuQiuRong.Chat.Businesses.Users;
using LiuQiuRong.Chat.Businesses.Users.Dtos;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace LiuQiuRong.Chat.Web.Pages
{
    public class RegisterModel : PageModel
    {
        private readonly IUserServices _userServices;

        public RegisterModel(IUserServices userServices)
        {
            _userServices = userServices;
        }

        public void OnGet()
        {

        }

        [BindProperty]
        public string Account { get; set; }
        [BindProperty]
        public string UserName { get; set; }
        [BindProperty]
        public string PassWord { get; set; }
        [BindProperty]
        public string RePassWord { get; set; }

        public IActionResult OnPostSubmit()
        {
            var user = new UserUnsafeDto
            {
                Phone = Account,
                Password = PassWord,
                UserName = UserName,
                CreateDate = DateTime.Now,
                UserId = Guid.NewGuid()
            };
            var result = _userServices.Add(user);
            return new JsonResult(result);
        }

    }
}